﻿@using System
@using System.Linq
@using YYBlog.Core.Entity;
@using YYBlog.Core.Extensions
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<YYBlog.Core.ViewProjections.Admin.BlogPostEditViewModel>
@{
    Layout = "_AdminLayout.cshtml";
}
@section PostStyle{
    <link href="/Content/css/bootstrap-markdown.min.css" rel="stylesheet" />
}
<div class="title">添加文章</div>
<div class="card">
    <div class="card-body">
        <form method="post" role="form" action="/yy-admin/posts/edit/@Model.BlogPost.Id">
            <div class="form-group">
                <input id="post-title" type="text" class="form-control" name="Title" placeholder="标题" value="@Model.BlogPost.Title" required />
            </div>
            <div class="form-group">
                <input type="text" class="form-control" name="TitleSlug" placeholder="固定链接Key" value="@Model.BlogPost.TitleSlug" required />
            </div>
            <div class="form-group">
                <textarea id="post-content" data-provide="markdown" rows="30" name="MarkDown" placeholder="内容" required>@Model.BlogPost.MarkDown</textarea>
            </div>
            <div class="form-group">
                <input name="Tags" id="tags" class="form-control" value="@(Model.BlogPost.Tags==null?string.Empty:string.Join(",",Model.BlogPost.Tags.Split(',').Select(s=>s.AsTag().Name)))" />
            </div>
            <div class="form-group">
                <div class="form-check">
                    <label class="form-check-label">
                        <input class="form-check-input" name="Published" value="true" @(Model.BlogPost.PubDate <= DateTime.UtcNow && Model.BlogPost.Status == PublishStatus.Published ? "checked='checked'" : "") type="checkbox">发布
                    </label>
                </div>
            </div>
            <div class="form-group">

                <input id="pubdate" type="hidden" name="PubDate" value="@(Model.BlogPost.PubDate != DateTime.MinValue ? Model.BlogPost.PubDate : DateTime.UtcNow)" />
                <input type="submit" value="保存" class="btn btn-primary" />
            </div>
        </form>
    </div>
</div>
@section PostScripts{
    <script src="/Content/js/bootstrap-markdown.js"></script>
    <script src="/Content/js/bootstrap-markdown.zh.js"></script>
    <script src="/Content/js/jquery.tagsinput.js"></script>
    <script src="/Content/js/markdown.js"></script>
    <script>
        $('#tags').tagsInput({ 'width': '100%', 'defaultText': '添加标签' });
    </script>
}
